//
//  ChangeClassViewController.m
//  hello mui
//
//  Created by zhangtao on 15/9/14.
//  Copyright (c) 2015年 zt.td. All rights reserved.
//

#import "ChangeClassViewController.h"
#import "GradeTableViewController.h"
#import "ChooseGroupViewController.h"
#import "SchoolViewController.h"
typedef enum {
    GRADE     = 0,
    MATH      = 1,
    CHINESE   = 2,
    GROUP     = 3,
    DATESTE   = 4,
    SCHOOL  =5,
}Select;
@interface ChangeClassViewController ()
@property(nonatomic,strong)NSArray *gradeArray;  //年级
@property(nonatomic,strong)NSArray *dateSteArray;//学期
@property (weak, nonatomic) IBOutlet UIView *a;
@property (weak, nonatomic) IBOutlet UIView *b;
@property (weak, nonatomic) IBOutlet UIView *c;
@property (weak, nonatomic) IBOutlet UIView *d;



@end

@implementation ChangeClassViewController
@synthesize gradeArray;
@synthesize dateSteArray;

-(void)viewWillAppear:(BOOL)animated{
//    [self initLabel];
    [super viewWillAppear:animated];
//    self.tabBarController.tabBar.hidden = YES;
    self.gradeLabel.text = NSUSER_DEF(@"GRADE");
    self.dateStuLabel.text = NSUSER_DEF(@"DATA");
    self.schoolLabel.text = NSUSER_DEF(@"SCHOOL");
    self.groupLabel.text = NSUSER_DEF(@"GROUP");
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.title = @"切换年级、教材";
    self.view.backgroundColor = [UIColor colorWithRed:240/255.f green:240/255.f blue:240/255.f alpha:1];
    
    _a.layer.borderColor = _b.layer.borderColor = _c.layer.borderColor = [[UIColor clearColor]CGColor];
    _a.layer.borderWidth = _b.layer.borderWidth = _c.layer.borderWidth = 0;
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
   
    [self initArray];
    
}

-(void)initArray{
    gradeArray = [NSArray arrayWithObjects:@"一年级",@"二年级",@"三年级",@"四年级",@"五年级",@"六年级",@"初一",@"初二",@"初三",@"高一",@"高二",@"高三", nil];
    dateSteArray = [NSArray arrayWithObjects:@"上学期",@"下学期", nil];
}
- (IBAction)selectBtn:(UIButton *)sender {
    GradeTableViewController *grade = [[GradeTableViewController alloc]init];
    ChooseGroupViewController *group = [[ChooseGroupViewController alloc]initWithNibName:@"ChooseGroupViewController" bundle:nil];
    
    switch (sender.tag) {
        case GRADE:
            grade.array = gradeArray;
            grade.passValue = GRADE;
            grade.change = self;
            [self.navigationController pushViewController:grade animated:YES];
            break;
//        case MATH:
////            grade.array = mathArray;
//            return;
//        case CHINESE:
//            return;
        case GROUP:
            group.change = self;
            [self.navigationController pushViewController:group animated:YES];
            return;
        case DATESTE:
            grade.array = dateSteArray;
            grade.passValue = DATESTE;
            grade.change = self;
            [self.navigationController pushViewController:grade animated:YES];
            break;
        case SCHOOL:
            [self toSchoolVC];
            return;

        default:
            break;
    }
//    grade.change = self;
//    [self.navigationController pushViewController:grade animated:YES];
    
}

-(void)toSchoolVC{
   
//    
    NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
    if ([def valueForKey:@"shengID"]&&[def valueForKey:@"shiID"]&&[def valueForKey:@"areaID"]) {
         SchoolViewController *school = [[SchoolViewController alloc]initWithNibName:@"SchoolViewController" bundle:nil];
        school.change = self;
        [self.navigationController pushViewController:school animated:YES];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"请先选择地区" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initLabel{
    _gradeLabel.text = [NSString stringWithFormat:@"%@",NSUSER_DEF(@"GRADE")];
    _schoolLabel.text = [NSString stringWithFormat:@"%@",NSUSER_DEF(@"SCHOOL")];
    NSString *address;
    
    if (NSUSER_DEF(@"SHENG")) {
        address = [NSString stringWithFormat:@"%@",NSUSER_DEF(@"SHENG")];
        if (NSUSER_DEF(@"SHI")) {
            address = [address stringByAppendingString:[NSString stringWithFormat:@"%@",NSUSER_DEF(@"SHI")]];
            if (NSUSER_DEF(@"AREA")) {
                address = [address stringByAppendingString:[NSString stringWithFormat:@"%@",NSUSER_DEF(@"AREA") ]];
            }
        }
        _groupLabel.text = address;
        NSUSER_DEF_NORSET(address, @"GROUP");
    }
    
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
